function jiahongbg(index){	
	try{$("#listdectwo"+index).find("p").css({"color":"#008000"});}catch(e){}
}
function normalbg(index){
	try{$("#listdectwo"+index).find("p").css({"color":""});}catch(e){}
}
//返回
var isJump=false;
function greturn(){
	isJump=true;
	var index=parseInt(gretArr.length)-2;
	if(index<0)return;
	var jumpstr=gretArr[index];
	if(index>0){
		gretArr.splice(gretArr.length-1,1);
	}
	if(""==jumpstr||jumpstr=="gopage(6)"){
		if(go1){
			swapTab(config.tabflag);
		}else{
			goindex();
		}
		isJump=false;
	}else{
		eval(jumpstr);
	}
}
function goindex(){
	if(returnpage==1){
		searchMusicFunction(searchKey);
	}else if(returnpage==2){
		gopage(6);	
	}
}
//返回列表时当前播放歌曲定位
function goplayposition(){
	if(cur_index>7){
		var ytop=cur_index*55+55;
		jQuery(document).scrollTop(ytop);
	}
}
//提示文字
var toastTime=null;
function setToast(text){
	if(toastTime!=null){
		$('#toastId').stop(true,true);
		clearTimeout(toastTime);
	}
	$('#toastId').find("div").html(text);
	$('#toastId').css({'opacity':'1'});
}
var toastTime2=null;
var displayTime2=null;
function setToast2(text){
	if(toastTime2!=null){
		$('#toastId2').stop(true,true);
		clearTimeout(toastTime2);
		clearTimeout(displayTime2);
	}
	$("#toastId2").css({'display':'block'});
	$('#toastId2').find("div").html(text);
	var dw=$(document).width();
	var divw=$('#toastId2').find("div").width();
	var leftm=(dw-divw)/2;
	$('#toastId2').find("div").css({'margin-left':"'"+leftm+"px'"});
	
	$('#toastId2').css({'opacity':'1'});
	toastTime2=setTimeout(function(){
		$("#toastId2").animate({'opacity':'0'},1000);
		displayTime2=setTimeout(function(){$("#toastId2").css({'display':'none'});},1000);
	},1000);
}
function setToast3(html){
	if(toastTime2!=null){
		$('#toastId2').stop(true,true);
		clearTimeout(toastTime2);
		clearTimeout(displayTime2);
	}
	$("#toastId2").css({'display':'block'});
	$('#toastId2').html(html);
	var dw=$(document).width();
	var divw=$('#toastId2').find("div").width();
	var leftm=(dw-divw)/2;
	$('#toastId2').find("div").css({'margin-left':"'"+leftm+"px'"});
	
	$('#toastId2').css({'opacity':'1'});
	toastTime2=setTimeout(function(){
		$("#toastId2").animate({'opacity':'0'},1000);
		displayTime2=setTimeout(function(){$("#toastId2").css({'display':'none'});},1000);
	},1000);
}
function loadinghtml(){
	moreloadhtml(1);
	return '<div style="width:100%;"><div id="padload" style="display: block;margin:0 auto;width: 280px;" class="loading"><span class="padloadIcon"></span><span class="pullUpLabel" style="font-size:1.27em;">正在搜索，好音乐马上就来...</span></div></div>';
}
var allowLoadMore=0;
function moreloadhtml(flag){
	if(1==flag){
		allowLoadMore=0;
		$("#morebtnId").html('');
	}else if(2==flag){
		allowLoadMore=1;
		$("#morebtnId").html('<div id="padload" style="display: block;margin:0 auto;width: 80px;" class="loading"><span class="pullUpLabel" style="font-size:1.27em;">获取更多</span></div>');
	}else if(3==flag){
		allowLoadMore=0;
		$("#morebtnId").html('<div id="padload" style="display: block;margin:0 auto;width: 150px;" class="loading"><span class="padloadIcon"></span><span class="pullUpLabel" style="font-size:1.27em;">正在加载...</span></div>');
	}
}
function requestErr(){
	setToast3('<div style="color:#fff;background: rgba(0, 0, 0, 0.6);border-radius: 2px;padding: 2px;text-align: center;width:170px;margin: 0 auto;">请求失败,请检查网络</div>');
}
function jsonError(){
}
function Err() {
	//通用错函数
}
function setHfbg(){
	setlrch();
}
function setlrch(){
	var h=document.documentElement.clientHeight-120;
	$('#lrcId').css({"height":h+"px"});
}
function dsExe(){
	config.qk_loading=0;
	p_song_flag=0;
}
function commdown(e,flag){
	return;
	var tdurl='';	
	if(flag==1){
		tdurl='';
	}
	if(browser.versions.ios){
		tdurl='http://itunes.apple.com/cn/app/id416751058?mt=8';
	}
	window.location=tdurl;
	config.stopBubble(e);
}
var adflag = false;
function hideAD(){
	$("#header").css("top","0px");
	$("#content").css("padding-top","44px");
	$("#hsyAD").remove();
	adflag = true;
}
config.tabflag=1;
function swapTab(flag,g_flag){//1推荐,2为曲库
	commHide();
	$(".nav").show();
	$("#tabtjId,#tabqkId,#tabmyId,#tabmoreId").removeClass("spanNow");
	$("#commplayId").show();
	config.qk_type=flag;
	config.tabflag=flag;
	moreloadhtml(1);
	gretArr=[""];
	if(1==flag){
		$("#tabtjId").addClass("spanNow");
		$("#tjId").show();
		$("#con_artid").hide();
		jQuery(window).scrollTop(lastposarr["tj"]);
		$("#morebtnId").html(lastposarr["tjmore"]);
		if(lastposarr["tjmore"].indexOf("更多")!=-1){
			allowLoadMore=1;
		}
	}else if(2==flag){
		$("#tabqkId").addClass("spanNow");
		//$("#con_sreachId").show();
		$("#qukuId").show();
		
		//if(!isHTML5() || (!MediaPlayer.canPlayM4a && !MediaPlayer.canPlayAac)){
			//$("#qukuId,#tjId,#conmyId,#condownId").html("同学你的手机不支持html5播放");
		//}else{
			loadquku();
		//}
		jQuery(window).scrollTop(lastposarr["qk"]);
		$("#morebtnId").html(lastposarr["qkmore"]);
	}else if(3==flag){
		$("#tabmyId").addClass("spanNow");
		$("#conmyId").show();
		$("#con_gdtextId").hide();
		loadGeshou();
		jQuery(window).scrollTop(lastposarr["my"]);
	}else if(4==flag){
		return;
		$("#tabmoreId").addClass("spanNow");
		var app_pic="../i/1/app3.jpg";
		var app_name="下载永久音乐WindowsPhone版";
		var cabdown='';
		var apkdown='';
		app_down='<a href="'+cabdown+'" class="app_downbtn"><span>下 载</span></a>';
		var html=[];
		if(browser.versions.ios){
			html[html.length]='<div class="m_title">';
          	html[html.length]='把百万歌曲装进口袋<br/>随时随地想听就听';
            html[html.length]='</div>';
            html[html.length]='<div class="m_con">';
            html[html.length]='<div class="m_conleft">';    
            html[html.length]='<img src="./App/Tpl/default/wap/music/images/ip.png" width="156" />';    
            html[html.length]='</div>';          
            html[html.length]='<div class="m_conright">';

            html[html.length]='<img src="./App/Tpl/default/wap/music/images/logo.png" width="146" />';    
          	html[html.length]='<img src="../i/1/load.png" width="146" onclick="openit();"/>';
          	html[html.length]='</div></div>';
          	html[html.length]='<div class="m_foot">@永久音乐触屏版</div>';
			$("#condownId").html(html.join(''));
		}else{
			html[html.length]='<div class="m_title">';
          	html[html.length]='把百万歌曲装进口袋<br/>随时随地想听就听';
            html[html.length]='</div>';
            html[html.length]='<div class="m_con">';
            html[html.length]='<div class="m_conleft">';    
            html[html.length]='<img src="../i/1/and.png" width="156" />';    
            html[html.length]='</div>';          
            html[html.length]='<div class="m_conright">';
                      
            html[html.length]='<img src="./App/Tpl/default/wap/music/images/logo.png" width="146" />';    
          	html[html.length]='<a href="javascript:downapk(\''+apkdown+'\')"><img src="../i/1/load.png" width="146" /></a>';
          	html[html.length]='</div></div>';
          	html[html.length]='<div class="m_foot">@永久音乐触屏版</div>';
          	$("#condownId").html(html.join(''));
		}
		$("#condownId").show();
	}
}
function gopage(flag,tilte){
	commHide();
	config.qk_type=flag;
	if(2==flag || 11==flag || 10==flag || 12==flag || 13==flag){//榜单，心情歌曲，专题，DJ
		showplaybtn();
		$("#con_gdtextId").show();
	}else if(5==flag){//默认列表，二级列表
		$("#returnId .tit").html(tilte);
		$("#returnId").show();
		$("#oneContextId").show();
		$("#commplayId").show();
	}else if(6==flag){//歌词页
		moreloadhtml(1);
		if(isJump){
			isJump = false;
		}else{
			gretArr[gretArr.length]='gopage('+flag+')';
		}
		$("#navplayId").show();
		$("#lrcId").show();
		$("#lrcplayId").show();
	}else if(7==flag){
		showplaybtn();
		$("#con_phbid").show();
	}else if(8==flag){//歌手页
		showplaybtn();
		$("#returnId .tit").html(tilte);
		$("#returnId").show();
		$("#gsContextId").show();
		$("#commplayId").show();
	}else if(9==flag){//歌手歌曲
		showplaybtn();
		$("#con_artid").show();
	}else if(10==flag){
		showplaybtn();
		$("#con_arttextid").show();
		$("#artdaId").hide();
		$("#artalbumId").show();
	}else if(11==flag){
		showplaybtn();
		$("#con_flid").show();
	}else if(12==flag){//推荐首页的轮播广告点击加载的歌曲
		showplaybtn();
		$("#con_gdtextId").show();
	}else if(13==flag){
		showplaybtn();
		$("#con_sreachId").show();
		$("#searchtipsId").show();
	}else if(14==flag){
		showplaybtn();
		$("#con_albumtextId").show();
	}else if(15==flag){//搜索
		showplaybtn();
		$("#con_sreachId").show();
		$("#searchContextId").show();		
		$("#searchdqId").show();
	}
}
var lastposarr=new Array();
function commHide(){
	var ytop=jQuery(window).scrollTop()
	if($("#tjId").is(":visible")){
		lastposarr["tj"]=ytop;
		lastposarr["tjmore"]=$("#morebtnId").html();
	}else if($("#qukuId").is(":visible")){
		lastposarr["qk"]=ytop;
		lastposarr["qkmore"]=$("#morebtnId").html();
	}else if($("#conmyId").is(":visible")){
		lastposarr["my"]=ytop;
		lastposarr["mymore"]=$("#morebtnId").html();
	}else if($("#condownId").is(":visible")){
		lastposarr["down"]=ytop;
		lastposarr["downmore"]=$("#morebtnId").html();
	}else if($("#gsContextId").is(":visible")){
		lastposarr["gscon"]=ytop;
		lastposarr["gsconmore"]=$("#morebtnId").html();
	}else if($("#con_gdtextId").is(":visible")){
		lastposarr["gsmcon"]=ytop;
		lastposarr["gsmconmore"]=$("#morebtnId").html();
	}else if($("#oneContextId").is(":visible")){
		lastposarr["onecon"]=ytop;
		lastposarr["oneconmore"]=$("#morebtnId").html();
	}else if($("#con_artid").is(":visible")){
		lastposarr["twoartcon"]=ytop;
		lastposarr["twoartconmore"]=$("#morebtnId").html();
	}else if($("#con_flid").is(":visible")){
		lastposarr["twoflcon"]=ytop;
		lastposarr["twoflconmore"]=$("#morebtnId").html();
	}else if($("#artdaId").is(":visible")){
		lastposarr["artdaid"]=ytop;
		lastposarr["artdaidmore"]=$("#morebtnId").html();
	}else if($("#searchdqId").is(":visible")){
		lastposarr["searchdqId"]=ytop;
		lastposarr["searchdqIdmore"]=$("#morebtnId").html();
	}else if($("#searchartId").is(":visible")){
		lastposarr["searchartId"]=ytop;
		lastposarr["searchartIdmore"]=$("#morebtnId").html();
	}else if($("#searchalbumId").is(":visible")){
		lastposarr["searchalbumId"]=ytop;
		lastposarr["searchalbumIdmore"]=$("#morebtnId").html();
	}
	$("#tjId,#qukuId,#conmyId,#condownId,#oneContextId,#gsContextId,#returnId,#lrcId,#twoContextId,#con_sreachId,#searchtipsId,#searchContextId").hide();
	$("#lrcplayId,#navplayId,.nav,#commplayId").hide();
	$("#twoContextId .twocommdiv").hide();
	$("#searchartId,#searchalbumId,#searchdqId").hide();
}
function showplaybtn(){
	$("#twoContextId").show();
	$("#commplayId").show();
	$("#returnId").show();
}
//加载更多
function pullUpAction(){
	try{
		if(config.qk_type==5){//第一级分类,排行榜内容页1000
			moreloadhtml(3);
			var sometreeobj = config.TreeArr.child[config.curr_index].child;
			var len=sometreeobj.length;
			if(len>G_PR){
				if(len>(G_SUM+G_PR)){
					$("#oneContextId").append(onefldata(G_SUM,(G_SUM+G_PR),config.curr_index));
					G_SUM=G_SUM+G_PR;
					moreloadhtml(2);
				}else{
					$("#oneContextId").append(onefldata(G_SUM,len,config.curr_index));
					G_SUM=G_SUM+G_PR;
					moreloadhtml(1);
				}
			}else{moreloadhtml(1);}
		}else if(config.qk_type==1){//推荐数据
			loadData();
		}else if(config.qk_type==10){//永久专辑数据
			loadZhuantiMusic(current_zjid,current_name,current_pic,current_intro);
		}else if(config.qk_type==11){//专题
			loadZtMusic(currentact,currentopt,current_zjid,current_tasteid);
		}else if(config.qk_type==12){//Dj
			loadDjMusic(current_flagcls,current_reqa,current_flagstr);
		}else if(config.qk_type==13){//Dj专辑
			loadDjZjMusic(current_djzjid,current_djzjname);	
		}else if(config.qk_type==8){//分类里的歌手
			loadClsGeshou(currentClsId,currentClsName);
		}else if(config.qk_type==9){//歌手歌曲
			loadGsMusic(currentArtistId,currentArtistName,currentArtistPic,currentArtistIntro);
		}else if(config.qk_type==15){//搜索
			searchMusic();
		}
	}catch(e){}
}

var g_parentid=-1;
var g_id=-1;
var g_name="";
var g_intro="";
var g_source=-1;
var g_pic="";
var g_flag=0;
//点击列表时执行
function commonClick(source,intro,name,id,parentid,pic,flag){
	g_parentid=parentid;
	g_id=id;
	g_name=name;
	g_intro=intro;
	g_source=source;
	g_pic=pic;
	g_flag=flag;
	if(source==13){//专题歌曲
		ShowZhuantiMusic(id,name,pic,intro);
	}else if(source==0 || source==-1){
		loadtjData(1);//推荐专题歌曲
	}else if(source==1){//心情歌曲
		xinQingGeQu(id,name,pic,intro);
	}else if(source==5){//榜单
		someBang(id,name,pic,intro);
	}else if(source==8){//歌手歌曲
		showGsMusic(id,name,pic,intro);
	}
}
function backmusic(data){
	var musicList=data.musiclist;
	var bigStr = musicBigString(musicList,0,0);
	$("#twoContextId #con_gdtextId .play_listall").html(bigStr);
	bigStr="";
}
function musicBigString(arr,page,rn){
	var html=[];
	var rowsum=rn*page-rn;
	if(page<=1){
		gdtempPlayArr=arr;
	}else{
		for(var i=0;i<arr.length;i++){
			gdtempPlayArr.push(arr[i]);
		}
	}
	for(var i=0;i<arr.length;i++){
		var someObj=arr[i];
		var name = someObj.mname;
		if(typeof(name)=="undefined" && someObj.name){
			name=someObj.name;
		}
		if(typeof(name)=="undefined" && someObj.NAME){
			name=someObj.NAME;
		}
		var artist = someObj.artist;
		if(typeof(artist)=="undefined" && someObj.mauther){
			artist = someObj.mauther;
		}
		if(typeof(artist)=="undefined" && someObj.ARTIST){
			artist = someObj.ARTIST;
		}		


		var albumName = someObj.album;
		if(typeof(albumName)=="undefined" && someObj.malbum){
			albumName = someObj.malbum;
		}
		if(typeof(albumName)=="undefined" && someObj.ALBUM){
			albumName = someObj.ALBUM;
		}
		if(!albumName || albumName==null){
			albumName = "";
		}
		var zmalbum="&nbsp;—&nbsp;";
		if(albumName==""){
			zmalbum="";
		}
		var tsum=rowsum+(i+1);
		html[html.length]='<div class="listtwo" onclick="commplay('+(rowsum+i)+')">';
		html[html.length]='<div class="numbertwo">'+tsum+'</div>';
		html[html.length]='<div class="more3" onclick="commdown(event)"><img src="./App/Tpl/default/wap/music/images/disclosure_indicator@2x.png"></div>';
		html[html.length]='<div class="listdectwo" id="listdectwo'+i+'">';
		html[html.length]='<p>'+name+'</p>';					
		html[html.length]='<p class="listtext"><em>'+artist+'</em>'+zmalbum+albumName+'</p>';					
		html[html.length]='</div>';					
		html[html.length]='</div>';
	}
	return html.join("");	
}
//我的默认列表
function showplsth(flag){
	gopage(5,"默认列表");
	last_index=-1;
	$("#oneContextId").html(loadinghtml());
	if(isJump){
		isJump = false;
	}else{
		if(gretArr[gretArr.length-1].indexOf('showplsth')>-1){
			gretArr[gretArr.length-1]='showplsth('+flag+')';
		}else{
			gretArr[gretArr.length]='showplsth('+flag+')';
		}
	}
	var html=[];
	if(tempPlayArr && tempPlayArr.length>0){
		html[html.length]='<div class="playlist">';
		html[html.length]='<div class="play_listtitle"><span>正在播放：</span><span>试听列表</span></div>';
		html[html.length]='<div class="play_listnum">共<span>'+tempPlayArr.length+'</span>首歌曲</div>';
		html[html.length]='<div class="play_listall">';
		for(var i=0;i<tempPlayArr.length;i++){
			var mobj=tempPlayArr[i];
			var num = i + 1;
			var rid=mobj.rid;
			if(typeof(rid)=="undefined" && mobj.id){
				rid=mobj.id;
			}
			if(typeof(rid)=="undefined" && mobj.musicrid){
				rid=mobj.musicrid;
			}
			if(typeof(rid)=="undefined" && mobj.MUSICRID){
				rid=mobj.MUSICRID;
			}
			var name=mobj.songName;
			if(typeof(name)=="undefined" && mobj.mname){
				name=mobj.mname;
			}
			if(typeof(name)=="undefined" && mobj.name){
				name=mobj.name;
			}
			if(typeof(name)=="undefined" && mobj.NAME){
				name=mobj.NAME;
			}
			
			var artist = mobj.artist;
			if(typeof(artist)=="undefined" && mobj.mauther){
				artist = mobj.mauther;
			}
			if(typeof(artist)=="undefined" && mobj.ARTIST){
				artist = mobj.ARTIST;
			}
			var albumName = mobj.album;
			if(typeof(albumName)=="undefined" && mobj.malbum){
				albumName = mobj.malbum;
			}
			if(typeof(albumName)=="undefined" && mobj.ALBUM){
				albumName = mobj.ALBUM;
			}
			if(!albumName || albumName==null){
				albumName = "";
			}
			var color1="#BABABA";
			var color2="#141414";
			var color3="#ABABAB";
			if(g_rid==rid){
				color1="#FFCC00";
				color2="#FFCC00";
				color3="#FFCC00";
			}
			var zmalbum="&nbsp;—&nbsp;";
			if(albumName==""){
				zmalbum="";
			}
			html[html.length]='<div class="listtwo" onclick="setcolor_plsth(\'plst_'+rid+'\'); playsindex('+i+');" id="plst_'+rid+'">';
			html[html.length]='<div class="numbertwo" style="color:'+color1+'">'+num+'</div>';
			html[html.length]='<div class="more"></div>';
			html[html.length]='<div class="listdectwo">';
			html[html.length]='<p style="color:'+color2+'">'+name+'</p>';					
			html[html.length]='<p class="listtext" style="color:'+color3+'"><em>'+artist+'</em>'+zmalbum+albumName+'</p>';					
			html[html.length]='</div>';					
			html[html.length]='</div>';
		}
	}else{
		html[html.length]='<div class="playlist">';
		html[html.length]='<div class="play_listtitle"><span>正在播放：</span><span>试听列表</span></div>';
		html[html.length]='<div class="play_listnum">共<span>0</span>首歌曲</div>';
		html[html.length]='<div class="play_listall">';
	}
	html[html.length]='</div></div>';
	$("#oneContextId").html(html.join(""));
	goplayposition();
}

function setcolor_plsth(id) {
	try {
		jQuery(".play_listall .listtwo").each(function(){
			jQuery(".numbertwo",$(this)).css("color","#BABABA");
			jQuery(".listdectwo p:eq(0)",$(this)).css("color","#141414");
			jQuery(".listdectwo p.listtext",$(this)).css("color","#ABABAB");
		});
		jQuery("#"+id+" .numbertwo").css("color","#FFCC00");
		jQuery("#"+id+" .listdectwo p:eq(0)").css("color","#FFCC00");
		jQuery("#"+id+" .listdectwo p.listtext").css("color","#FFCC00");
	} catch(e) {}
}